// 解法一：遍历将节点放在数组中，然后取中间值
function middleNode(head) {
    let arr = [];
    while (head != null) {
        arr.push(head);
        head = head.next;
    }
    return arr[Math.ceil((arr.length - 1) / 2)];
}

// 解法二：利用双指针，快指针走两步，慢指针走一步，快指针走完，慢指针则为中间值
function middleNode(head) {
    if (head == null) return null;
    let fast = head, slow = head;
    while (fast != null && fast.next != null) {
        fast = fast.next.next;
        slow = slow.next;
    }
    return slow;
}